import { GeneraDataType } from "@/interface";
import { message } from "ant-design-vue";
import { updateStatusApi } from "@/api/configCenter/exchangeRate";
export default function OperationHook(state: GeneraDataType) {
  const { dialogOpts, getData } = state;
  const addHandle = () => {
    dialogOpts.title = "新增汇率";
    dialogOpts.width = "520px";
    dialogOpts.type = 1;
    dialogOpts.component = "addRate";
    dialogOpts.visible = true;
  };
  const editHandle = (row: ExchangeRateManagement.ListRows) => {
    dialogOpts.title = "编辑汇率";
    dialogOpts.width = "520px";
    dialogOpts.type = 2;
    dialogOpts.component = "addRate";
    dialogOpts.passData = row;
    dialogOpts.visible = true;
  };
  // 修改状态
  const changeStatusHandle = (row: ExchangeRateManagement.ListRows) => {
    const params: any = {
      id: row.id,
      status: row.status ? 0 : 1
    };
    updateStatusApi(params).then((res: any) => {
      const { code } = res;
      if (code === 200) {
        message.success("操作成功!");
        getData();
      }
    });
  };
  return {
    editHandle,
    addHandle,
    changeStatusHandle
  };
}
